// firstPackage/pages/busJoinManagerList/busJoinManagerList.js

import {
  bussinessManagerList,
  bussinessManagerDeal
} from "../../../service/manager_service"
let app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    themeStyle: "",
    switchArr: [
      {
        title: "未处理",
        key: false,
      },
      {
        title: "已处理",
        key: true
      },
    ],
    exStatus: 0,
    page: 0,
    pageSize: 200,
    isDeal: false,
    dataList: [

    ],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.bussinessManagerList();
  },



  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    if (app.globalData.themeStyle) {
      this.setData({
        themeStyle: app.globalData.themeStyle
      })
    }
  },

  switchAction(e) {
    let index = e.currentTarget.dataset.index;
    let item = e.currentTarget.dataset.item;
    this.setData({
      exStatus: index,
      isDeal: item.key
    })
    this.bussinessManagerList();
  },
  //列表
  bussinessManagerList() {
    wx.showLoading();
    bussinessManagerList(this.data.page, this.data.pageSize, this.data.isDeal).then(res => {
      wx.hideLoading();
      console.log("JJLog:商务列表:" + JSON.stringify(res));
      if (res.code == 200) {
        this.setData({
          dataList: res.data || []
        })
      }
    }).catch(err => {
      wx.hideLoading();
      wx.showToast({
        title: err || "查询失败",
        icon: "none"
      })
      console.error("JJLog:bussinessManagerList", err);
    })
  },
  //处理商务
  busDealAction(e) {
    let id = e.currentTarget.dataset.id;
    wx.showModal({
      title: '提示',
      content: '是否已处理此商务',
      confirmColor: "#FF0000",
      success: res => {
        if (res.confirm) {
          this.bussinessManagerDeal(id);
        }
      }
    })


  },
  bussinessManagerDeal(id) {
    wx.showLoading();
    bussinessManagerDeal(id).then(res => {
      wx.hideLoading();
      if (res.code == 200) {
        wx.showToast({
          title: '操作成功',
          icon: "success"
        })
        this.bussinessManagerList();
      }
    }).catch(err => {
      wx.hideLoading();
      wx.showToast({
        title: err || "操作失败",
        icon: "none"
      })
      console.error("JJLog:bussinessManagerDeal", err);
    })
  },


  callPhoneAction(e) {
    let phone = e.currentTarget.dataset.phone;
    wx.makePhoneCall({
      phoneNumber: phone,
      fail: err => {

      }
    })
  },



})